<!--
* description: 备件清单维护历史查询
* author: xiaochengzuan
* createdDate: 2021-3-1
-->
<template>
  <div class="app-container app-container-table">
    <one-table-template
      ref="multipleTable"
      :key="oneTableKey"
      :dynamic-buttons="tableButtons"
      :dynamic-components="tableComponents"
      :dynamic-api-config="apiConfig"
      :dynamic-table-cols="tableCols"
      :dynamic-form-fields="formField"
      :dynamic-is-show-select="false"
      :dynamic-is-init-table="true"
      :dynamic-api-style="'restful'"
      :callback-obj="callbackObj"
    />
  </div>
</template>
<script>
import { oneTableWithViewTemplateMixins } from '@/components/mixins/oneTableWithViewTemplateMixins'
import OneTableTemplate from '@/components/templates/oneTable'
import Vue from 'vue'

import { orgApis } from '@/api/pabasicdataapi'
import { exportExcel } from '@/utils/getTimeString.js'

export default {
  name: 'MaintenanceHistoryQueryOfSparePartsList',

  components: {
    OneTableTemplate
  },
  // 组件混入对象
  mixins: [oneTableWithViewTemplateMixins],

  // 阻塞路由预加载网格中组件的数据
  beforeRouteEnter(to, from, next) {
    Vue.prototype.$ConfigCache.CacheConfig.initData([to.path, ''], function() {
      next()
    })
  },

  data() {
    // 页面标识（与上面beforeRouteEnter中的对应）
    const viewPageCode = this.$route.path

    // 绑定事件配置化事件
    this.$ConfigCache.CacheConfig.bindEvent(this, [viewPageCode])

    return {
      icon: 'el-icon-arrow-down',
      status: false,
      editRowData: {},
      selectiondata: null,
      // 网格查询API配置对象
      apiConfig: orgApis.maintenanceHistoryQueryOfSparePartsListquery,
      columnStyle({ row, column, rowIndex, columnIndex }) {
        if (
          (columnIndex === 8 && parseFloat(row.profitQuarters) <= 30) ||
          (columnIndex === 12 && parseFloat(row.outletsQuarters) < 25)
        ) {
          return 'background:red'
        } else if (
          (columnIndex === 8 && parseFloat(row.profitQuarters) > 35) ||
          (columnIndex === 12 && parseFloat(row.outletsQuarters) > 30)
        ) {
          return 'background:yellow'
        }
      },
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: 'btnKey1',
          type: 'primary',
          size: 'small',
          name: 'search',
          clickEvent: () => this.queryTable(1),
          text: this.$t('sys.button.query'), // 查询
          position: 'right',
          fuzzySearch: true
        },
        {
          compKey: 'btnKey3',
          size: 'small',
          clickEvent: () => this.exportExcel111(),
          text: '导出',
          name: 'export',
          position: 'right'
        },
        {
          compKey: 'btnKey2',
          size: 'small',
          name: 'reset',
          clickEvent: () => this.reset(),
          text: this.$t('sys.button.reset'),
          position: 'right' // 重置
        }

      ],

      // 动态组件-查询条件
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
            .tableComponents
          : [
            //   {
            //     compKey: "compKey1",
            //     labelName: "维修类型：",
            //     codeField: "maintenanceType",
            //     component: () => import("@/components/org/LookupValue"),
            //     oFields: "statusId,statusText",
            //     options: [
            //       { statusId: "0", statusText: "保养件" },
            //       { statusId: "1", statusText: "易损件" },
            //       { statusId: "2", statusText: "事故件" },
            //       { statusId: "3", statusText: "轮胎" },
            //       { statusId: "4", statusText: "精品" },
            //     ],
            //     type: "dropdownList",
            //     isMul: false,
            //     isMust: true,
            //   },
            {
              compKey: 'compKey2',
              labelName: '备件编码：',
              codeField: 'partNo',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMul: false,
              isMust: true
            },
            {
              compKey: 'compKey3',
              labelName: '备件名称：',
              codeField: 'partName',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMul: false,
              isMust: true
            },
            {
              compKey: 'compKey4',
              labelName: '备件状态：',
              codeField: 'partStatus',
              component: () => import('@/components/org/commonSelect'),
              customObj: {
                api: orgApis.maintenanceHistoryQueryOfSparePartsListdown
              },
              type: 'dropdownList',
              isMul: false,
              isMust: true
            },
            {
              compKey: 'compKey5',
              labelName: '备件类别：',
              codeField: 'partRepairType',
              component: () => import('@/components/org/commonSelect'),
              customObj: {
                api: orgApis.maintenanceHistoryQueryOfSparePartsListdown1
              },
              type: 'dropdownList',
              isMul: false,
              isMust: true
            },
            {
              compKey: 'compKey7',
              labelName: '供应商：',
              codeField: 'supplierFullName',
              component: () => import('@/components/ve/multipleSearchInput'),
              type: 'inputText',
              isMul: false,
              isMust: false,
              dataToObject: {
                // 控制弹窗页面 搜索 网格 元素
                tableComponents: [
                  {
                    compKey: 'compKey1',
                    labelName: '供应商编码：',
                    codeField: 'supplierCode',
                    component: () => import('@/components/org/commonInput'),
                    type: 'inputText',
                    isMust: true,
                    span: 8
                  },
                  {
                    compKey: 'compKey2',
                    labelName: '供应商简称：',
                    codeField: 'supplierShortName',
                    component: () => import('@/components/org/commonInput'),
                    type: 'inputText',
                    isMust: true,
                    span: 8
                  },
                  {
                    compKey: 'compKey3',
                    labelName: '状态：',
                    codeField: 'isEnable',
                    component: () => import('@/components/org/LookupValue'),
                    oFields: 'statusId,statusText',
                    options: [
                      { statusId: '1', statusText: '启用' },
                      { statusId: '0', statusText: '禁用' }
                    ],
                    type: 'dropdownList',
                    isMust: true,
                    span: 8
                  }
                ],
                tableCols: [
                  {
                    prop: 'supplierCode',
                    label: '供应商编码'
                  },
                  {
                    prop: 'supplierShortName',
                    label: '供应商简称'
                  },
                  {
                    prop: 'supplierFullName',
                    label: '供应商全称'
                  },
                  {
                    prop: 'supplierAddr',
                    label: '详细地址'
                  },
                  {
                    prop: 'linkMan',
                    label: '联系人'
                  },
                  {
                    prop: 'linkManTel',
                    label: '联系电话'
                  },
                  {
                    prop: 'isEnableCn',
                    label: '状态'
                  },
                  {
                    prop: 'remark',
                    label: '备注'
                  }
                ],
                formField: {
                  supplierCode: '',
                  supplierShortName: '',
                  isEnable: ''
                },
                returnField: {
                  prop: 'supplierFullName',
                  label: '供应商全称'
                },
                api: orgApis.supplierInformationQueryquery
              },
              span: 6
            },

            {
              compKey: 'compKey8',
              labelName: '适用车型：',
              codeField: 'carConfigIdList',
              textField: 'carConfigCn',
              component: () => import('@/views/ve/planReport/components/multipleSearchInput'),
              type: 'inputText',
              isMul: false,
              isMust: false,
              dataToObject: {
                oFields: 'carConfigCode,carConfigCn',
                // 控制弹窗页面 搜索 网格 元素
                tableComponents: [
                  {
                    compKey: 'compKey1',
                    labelName: '车型编码：',
                    codeField: 'carConfigCode',
                    component: () => import('@/components/org/commonInput'),
                    isMust: true,
                    span: 8
                  },
                  {
                    compKey: 'compKey2',
                    labelName: '车型名称：',
                    codeField: 'carConfigCn',
                    component: () => import('@/components/org/commonInput'),
                    isMust: true,
                    span: 8
                  }
                ],
                tableCols: [
                  {
                    prop: 'carConfigCode',
                    label: '车型编码'
                  },
                  {
                    prop: 'carConfigCn',
                    label: '车型名称'
                  },
                  {
                    prop: 'carSeriesCode',
                    label: '车系编码'
                  },
                  {
                    prop: 'carSeriesCn',
                    label: '车系名称'
                  }
                ],
                formField: {
                  carConfigCode: '',
                  carConfigCn: ''
                },
                returnField: {
                  prop: 'carConfigCode',
                  label: '车型名称'
                },
                api: {
                  APIUrl: 'mp/e3sh/spareparts/basic/partPriceQueryService/queryCarConfigCodes.do'
                }
              }
            },

            {
              compKey: 'compKey9',
              labelName: '修改时间：',
              codeField: 'lastUpdatedDate',
              component: () => import('@/components/org/datePicker/andtDatePicker'),
              type: 'andtDatePicker',
              isMul: false,
              isMust: false
            }
          ],

      // 动态生成网格列
      tableCols:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          : [
            {
              prop: 'releaseId',
              label: '主键ID',
              hidden: true,
              alwaysHidden: true
            },
            {
              prop: 'updateControlId',
              label: '并发控制ID',
              hidden: true,
              alwaysHidden: true
            },
            {
              prop: 'partNo',
              label: '备件编码'

            },
            {
              prop: 'partName',
              label: '备件名称'
            },
            {
              prop: 'modifier',
              label: '修改人'
            },

            {
              prop: 'lastUpdatedDate',
              label: '修改时间',
              width: '180px'
            },
            {
              prop: 'partStatusName',
              label: '备件状态'
            },
            {
              prop: 'isSale',
              label: '销售开关'
            },
            {
              prop: 'isOrder',
              label: '订货开关'
            },
            {
              prop: 'snp',
              label: 'SNP'
            },
            {
              prop: 'minOrderAmount',
              label: '最小起订量'
            },
            {
              prop: 'minSaleAmount',
              label: '最小销售数量'
            },
            {
              prop: 'unit',
              label: '备件单位'
            },
            {
              prop: 'orderPeriod',
              label: '订货周期'
            },
            {
              prop: 'arrivalPeriod',
              label: '到货周期'
            },
            {
              prop: 'specifications',
              label: '规格'
            },
            {
              prop: 'origin',
              label: '产地'
            },
            {
              prop: 'isOutsourcingCn',
              label: '允许外购'
            },
            {
              prop: 'isPetrospect',
              label: '追溯件'
            },

            {
              prop: 'bmcCode',
              label: '三电标识'
            },
            {
              prop: 'warrantyPeriod',
              label: '质保期(月)'
            },

            {
              prop: 'is3CCn',
              label: '是否3C件'
            },

            {
              prop: '3cPieceType',
              label: '3C件类型'
            },
            {
              prop: 'partStatusName1',
              label: '维修类型'
            },
            {
              prop: 'carConfigIdList',
              label: '适用车型'
            },

            {
              prop: 'supplierCode',
              label: '供应商编码'
            },
            {
              prop: 'supplierFullName',
              label: '供应商名称'
            },
            {
              prop: 'directDeliveryPiececn',
              label: '直送件'
            },

            {
              prop: 'vinPiececn',
              label: 'VIN件'
            },

            {
              prop: 'transportRestrictionscn',
              label: '运输限制'
            },

            {
              prop: 'abcTypecn',
              label: 'ABC类'
            },

            {
              prop: 'specialPiececn',
              label: '特殊备件'
            },

            {
              prop: 'keyPiececn',
              label: '重点备件'
            },

            {
              prop: 'replacePiece',
              label: '替换件'
            },

            {
              prop: 'length',
              label: '长(MM)'
            },
            {
              prop: 'width',
              label: '宽(MM)'
            },

            {
              prop: 'height',
              label: '高(MM)'
            },
            {
              prop: 'partCubage',
              label: '体积(MM3)'
            },

            {
              prop: 'chargedWeight',
              label: '重量(克)'
            },

            {
              prop: 'baleType',
              label: '包装类型'
            },

            {
              prop: 'cof',
              label: '摩擦系数'
            },
            {
              prop: 'partAttr',
              label: '备件属性'
            },

            {
              prop: 'lookupValueName',
              label: '自制件标识'
            },
            {
              prop: 'remark',
              label: '备注'
            }
          ],
      callbackObj: {
        // 手动勾选时
        onCheckSelect: (selection, row) => {
          this.selectiondata = selection
        },
        onCheckSelectChange: (selection) => {
          this.onCheckSelectChange1(selection)
        }
      },
      // 表单查询数据
      formField: this.$utils.getFormField(this,
        {
          partRepairType: '',
          supplierFullName: '',
          partNo: '',
          partName: '',
          partStatus: '',
          isSale: '',
          suppllierCode: '',
          carConfigIdList: '',
          codeField: '',
          lastUpdatedDate: ''
        },
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode]
      )
    }
  },
  watch: {
    'formField.orderStatus': {
      deep: true,
      handler: function(newV, oldV) {
        console.log('watch中：', newV)
        // this.querybystatus(newV)
        this.queryTable()
      }
    },
    'formField.lastUpdatedDate': {
      handler: function(newV) {
        if (newV === ',') {
          this.formField.lastUpdatedDate = ''
        }
      }
    }
  },
  mounted() {
    // 列表查询
    this.queryTable(1)
  },

  methods: {
    // 订单状态切换
    togglestatus() {
      if (this.status === true) {
        this.icon = 'el-icon-arrow-down'
        this.status = false
      } else {
        this.icon = 'el-icon-arrow-up'
        this.status = true
      }
      this.$refs.multipleTable.$refs.compKey11[0].curIsShow = this.status
      this.$refs.multipleTable.setTableHeight()
    },
    onCheckSelectChange1(selection) {
      var btn1 = this.tableButtons[2]
      var btn2 = this.tableButtons[3]
      const isCheck = selection && selection.length > 0
      btn1.disabled = !isCheck
      btn2.disabled = !isCheck
    },
    // 批量驳回、通过
    pass(type) {
      if (type === '0') {
        debugger
        this.editPopupsState = 'edit'
        this.editPopupsVisible = true
      }
    },

    exportExcel111() {
      exportExcel(this.formField, orgApis.maintenanceHistoryQueryOfSparePartsListexportexcel.APIUrl, orgApis.maintenanceHistoryQueryOfSparePartsListexportexcel.ServiceCode, '备件清单维护历史查询')
    }
  }
}
</script>
<style lang='scss' scoped>
.red {
  background: red;
}
</style>
